﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace PhoneApp1
{
    public partial class Page2 : PhoneApplicationPage
    {
        public Page2()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PinToStart("新闻1", "/icons/appbar.cancel.rest.png", "新闻1", "1111", "/icons/appbar.check.rest.png", "/Page2.xaml?id=1");
        }
        public static void PinToStart(string title, string image, string backTitle, string backContent, string backImage, string url)
        {
            //如果存在则删除，并在下面重新Pin到桌面            
            ShellTile oldTile = ShellTile.ActiveTiles.FirstOrDefault(e => e.NavigationUri.ToString().Contains(url));
            if (oldTile != null) { oldTile.Delete(); }
            //生成Tile         
            StandardTileData myTile = new StandardTileData { BackgroundImage = new Uri(image, UriKind.Relative), 
                Title = title, Count = 0,
                BackTitle = backTitle,
                BackContent = backContent,
                BackBackgroundImage = new Uri(backImage, UriKind.Relative) };
            //固定到开始界面    
            ShellTile.Create(new Uri(url, UriKind.Relative), myTile);
        }
    }
}